/*
 * File Name：DownLoadDetailHelper.java
 * Copyright：Copyright 2008-2014 CiWong.Inc. All Rights Reserved.
 * Description： DownLoadDetailHelper.java
 * Modify By：RES-jianpingliu
 * Modify Date：2014-4-8
 * Modify Type：Add
 */
package com.ciwong.epaper.util.download;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.ciwong.libs.utils.CWSys;
import com.ciwong.mobilelib.utils.BaseConstants;
import com.ciwong.mobilelib.utils.XiXinDBHelper;

/**
 * 应用下载数据库helper
 *
 * @author RES-jianpingliu
 * @version ciwong v.1.0 2014-4-8
 * @since ciwong v.1.0
 */
public class DownLoadHelper extends SQLiteOpenHelper implements XiXinDBHelper
{
    /**
     * 应用数据表名字
     */
    public static final String DB_NAME = DownLoadTable.TABLE_NAME;

    /**
     * 数据库版本号
     * 数据库发生改变的时候这个字段需要发生变化
     */
    public static final int DB_VERSION_NEW = 13;

    /**
     *
     * 构造方法
     *
     * @param context
     *            上下文
     * @param name
     *            数据库名字
     * @param factory
     *            产生Cursor对象的工厂类.
     * @param version
     *            版本号
     */
    public DownLoadHelper(Context context, String name, CursorFactory factory,
            int version)
    {
        super(context, name, factory, version);
    }

    /**
     *
     * 构造方法
     *
     * @param context
     *            上下文
     */
    public DownLoadHelper(Context context)
    {
        this(context,
                DB_NAME + CWSys.getSharedLong(
                        BaseConstants.SHARE_PRE_CURR_LOGIN_USER, 0),
                null, DB_VERSION_NEW);
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL(DownLoadTable.getCreateSql());
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        if(oldVersion<newVersion){
            db.execSQL("drop table if exists "+DownLoadTable.TABLE_NAME);
            db.execSQL(DownLoadTable.getCreateSql());
        }
    }
}
